\begin{tikzpicture}[scale=0.7]
    \tikzset {
        cube/.pic = {
            \draw[fill=white] [yslant=-0.5] (0,0) rectangle (1,1);
            \draw[fill=gray!20] [yslant=0.5] (1,-1) rectangle (2,0);
            \draw[pattern=dots] [yslant=0.5] (1,-1) rectangle (2,0);
            \draw[fill=white] [yslant=0.5,xslant=-1] (1,0) rectangle (2,1);
        }
    }

    \def \stack #1 {
        \foreach \x [count=\xi] in {#1} {
            \foreach \y [count=\yi] in \x {
                \ifthenelse {\y=0}{} {
                    \foreach \z in {1,...,\y} {
                        \draw (-\xi + \yi, -0.5*\xi-0.5*\yi+\z) pic[transform shape] {cube};
                    }
                }
            }
        }
    }

    \stack{{4,3,2,1},{3,2,1},{2,1},{1}}
\end{tikzpicture}
